package com.yhj.myapplication;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.yhj.myapplication.Model.CourseDetailModel;

import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

public class CouseDetailActivity extends AppCompatActivity {

    ImageView img;
    TextView textView,desTv,videoTv;
    RecyclerView recyclerView;
    String id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_couse_detail);
        img = findViewById(R.id.img);
        textView = findViewById(R.id.detaltv);
        recyclerView= findViewById(R.id.recycleview);
        desTv = findViewById(R.id.destv);

        desTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                desTv.setSelected(true);
                videoTv.setSelected(false);
                textView.setVisibility(View.VISIBLE);
                recyclerView.setVisibility(View.GONE);
//                recyclerView.setVisibility(View.INVISIBLE);
            }
        });
        videoTv = findViewById(R.id.videotv);
        desTv.setSelected(true);
        videoTv.setSelected(false);
        videoTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                desTv.setSelected(false);
                videoTv.setSelected(true);
                textView.setVisibility(View.GONE);
                recyclerView.setVisibility(View.VISIBLE);
            }
        });


        if (getIntent()!= null &&getIntent().getStringExtra("id")!= null){
            id = getIntent().getStringExtra("id");
        }

        RequestParams requestParams = new RequestParams("http://148.70.46.9:8080/boxuegu/bxg/chapterdetail");
        requestParams.addBodyParameter("id",id);

        x.http().post(requestParams, new Callback.CacheCallback<String>() {
            @Override
            public void onSuccess(String result) {
                Gson gson = new Gson();
                CourseDetailModel courseDetailModel = gson.fromJson(result,CourseDetailModel.class);
                Log.i("CouseDetailActivity",result);
                x.image().bind(img,courseDetailModel.data.img);
                textView.setText(courseDetailModel.data.des);
//                subjectList = exerciseDetailModel.data.subjectList;
//                myAdapter.notifyDataSetChanged();
//                title.setText(exerciseDetailModel.data.title);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }

            @Override
            public boolean onCache(String result) {
                return false;
            }
        });



    }

}
